//
//  SKUDefultQuestionTB.m
//  ZITHER
//
//  Created by weixin on 2018/8/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultQuestionTB.h"
#import "SKUDefultQuestionTBCell.h"
#import "SKUDetailTakeinVC.h"
#import "SKUDetailReceiveVC.h"
#import "SKUDefultQuestionTBCellText.h"
#import "SKUDefultQuestionUserimageTBCell.h"
#import "MainRefreshBezierPathV.h"//刷新询价 扇形图

@implementation SKUDefultQuestionTB

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.rowHeight = UITableViewAutomaticDimension;
        self.estimatedRowHeight = 1000;
        
        [self registerNib:[UINib nibWithNibName:@"SKUDefultQuestionUserimageTBCell" bundle:nil] forCellReuseIdentifier:@"SKUDefultQuestionUserimageTBCell"];
        [self registerNib:[UINib nibWithNibName:@"SKUDefultQuestionTBCellText" bundle:nil] forCellReuseIdentifier:@"SKUDefultQuestionTBCellText"];

   
    }
    return self;
}


#pragma MARK - 数据源
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    /* TODO: ================= 判断 cell 样式 =================*/

    if (indexPath.row == 0) {
        static NSString *sectionCell = @"SKUDefultQuestionTBCellText";
        SKUDefultQuestionTBCellText *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
        if (cell == nil) {
            cell = [[SKUDefultQuestionTBCellText alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
        }
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        cell.model = self.model;
        [cell setIndexCell:indexPath.row];
        
        return cell;
    }else{
        static NSString *sectionCell = @"SKUDefultQuestionUserimageTBCell";
        SKUDefultQuestionUserimageTBCell *cell = [tableView dequeueReusableCellWithIdentifier:sectionCell];
        if (cell == nil) {
            cell = [[SKUDefultQuestionUserimageTBCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sectionCell];
        }
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;
        cell.model = self.model;
        [cell setIndexCell:indexPath.row];
        return cell;

    }
 
}

//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//
//    if (indexPath.row == 0) {
//        return self.model.cellHeight1;
//    }else if (indexPath.row == 1){
//        return self.model.cellHeight2;
//    }else{
//        return self.model.cellHeight3;
//    }
//
//}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
        SKUDetailTakeinVC *vc = [[SKUDetailTakeinVC alloc]init];
        vc.leb.text = @"接受的报价";
        vc.goodsId = self.model.goodsId;
        [self.getNav pushViewController:vc animated:YES];
    }else if (indexPath.row == 1) {
        SKUDetailReceiveVC *vc = [[SKUDetailReceiveVC alloc]init];
        vc.indexType = @"1";
        vc.str = @"提醒商家报价";
        vc.leb.text = @"收到的报价";
        vc.goodsid = self.model.goodsId;
        [self.getNav pushViewController:vc animated:YES];
        
        
        
        
        
    }else{
        SKUDetailReceiveVC *vc = [[SKUDetailReceiveVC alloc]init];
        vc.indexType = @"2";
        vc.str = @"提醒商家报价";
        vc.leb.text = @"公开货源";
        vc.goodsid = self.model.goodsId;
        [self.getNav pushViewController:vc animated:YES];
    }
    
}





//设置表头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 80;
}

//添加标头中的内容
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 80)];
    
    UILabel *libelAge = [[UILabel alloc]initWithFrame:CGRectMake(20, 15, 10+[NSString textWidth:self.model.skuTicket font:20 height:20], 20)];
    libelAge.text = self.model.skuTicket;
    libelAge.textColor = [UIColor blackColor];
    [view addSubview:libelAge];
    
    UILabel *libelAge1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 45, [NSString textWidth:@"每次刷新询价可以获得0.5张询价票" font:20 height:20], 14)];
    NSString *str = [NSString stringWithFormat:@"每次刷新询价可以获得%@张询价票",self.model.skuTicketReward];
    libelAge1.text = str;
//    libelAge1.font = [UIFont systemFontOfSize:14];
    libelAge1.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14];

    libelAge1.textColor = [UIColor blackColor];
    [view addSubview:libelAge1];
    
    MainRefreshBezierPathV *RefreshV = [[MainRefreshBezierPathV alloc]initWithFrame:CGRectMake(kScreenW-50,20, 40, 40)];
    RefreshV.model = self.model;
    RefreshV.radius =  [self.model.refreshTime convertCurrentTimeChangeHours];
    [view addSubview:RefreshV];
    
//    UIButton *DownBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    DownBtn.frame = CGRectMake(kScreenW-50,20, 40, 40);
//    DownBtn.backgroundColor = [UIColor randomColor];
//    [view addSubview:DownBtn];
//    [DownBtn setCornerRadiusWithRadius:20 isMasks:YES];
//    [[DownBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
//        NSLog(@"点击刷新");
//    }];
    return view;
}



- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat sectionHeaderHeight = 80;
    if(scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
    
}

-(void)setModel:(skuDetailModel *)model{
    _model = model;
    
    [self reloadData];
    [self reloadData];
    NSLog(@"");
}
@end
